﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.ComponentModel;

namespace Skywave.Data
{
    [DataContract]
    public enum DataCompareTypes
    {
        [EnumMember]
        Equal = 1,
        [EnumMember]
        GreaterThan = 2,
        [EnumMember]
        LowerThan = 3,
        [EnumMember]
        GreaterOrEqual = 4,
        [EnumMember]
        LowerOrEqual = 5,
        [EnumMember]
        Contains = 6,
        [EnumMember]
        StartsWith = 7,
        [EnumMember]
        EndsWith = 8,
        [EnumMember]
        Among = 9,
        [EnumMember]
        BitwiseAnd = 10,
    }
    [DataContract]
    public enum DataConditionDataTypes
    {
        [EnumMember]
        Text = 1,
        [EnumMember]
        NumberInteger = 2,
        [EnumMember]
        NumberDouble = 3,
        [EnumMember]
        SingleSelection = 4,
        [EnumMember]
        MultiSelection = 5,
        [EnumMember]
        Date = 6,
        [EnumMember]
        Time = 7,
        [EnumMember]
        DateTime = 8,
        [EnumMember]
        Custom = 9,
        [EnumMember]
        Boolean = 10,
    }

    [DataContract]
    public class DataCondition : ICloneable
    {
        private bool _UI_AllowNull = false;
        /// <summary>
        /// UI_DataAllowNull Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        [DefaultValue(false)]
        public bool UI_AllowNull
        {
            get { return _UI_AllowNull; }
            set { _UI_AllowNull = value; }
        }

        private bool _UI_IsCustom = false;
        /// <summary>
        /// UI_IsCustom Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        [DefaultValue(false)]
        public bool UI_IsCustom
        {
            get { return _UI_IsCustom; }
            set { _UI_IsCustom = value; }
        }

        private int? _UI_MaximumHeight = null;
        /// <summary>
        /// UI_MaximumHeight Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public int? UI_MaximumHeight
        {
            get { return _UI_MaximumHeight; }
            set { _UI_MaximumHeight = value; }
        }

        private int? _UI_MinimumHeight = null;
        /// <summary>
        /// UI_MinimumHeight Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public int? UI_MinimumHeight
        {
            get { return _UI_MinimumHeight; }
            set { _UI_MinimumHeight = value; }
        }

        private string _Text;
        /// <summary>
        /// Text Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public string Text
        {
            get { return _Text; }
            set { _Text = value; }
        }

        private string _ColumnName;
        /// <summary>
        /// ColumnName Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public string ColumnName
        {
            get { return _ColumnName; }
            set { _ColumnName = value; }
        }

        private string _Category;
        /// <summary>
        /// Category Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public string Category
        {
            get { return _Category; }
            set { _Category = value; }
        }

        private string _ValueString;
        /// <summary>
        /// ValueString Property
        /// </summary>
        [DataMember]
        [Browsable(false)]
        public string ValueString
        {
            get { return _ValueString; }
            set { _ValueString = value; }
        }

        private int? _ValueInt;
        /// <summary>
        /// ValueInt Property
        /// </summary>
        [DataMember]
        [Browsable(false)]
        public int? ValueInt
        {
            get { return _ValueInt; }
            set { _ValueInt = value; }
        }

        private double? _ValueDouble;
        /// <summary>
        /// ValueDouble Property
        /// </summary>
        [DataMember]
        [Browsable(false)]
        public double? ValueDouble
        {
            get { return _ValueDouble; }
            set { _ValueDouble = value; }
        }

        private DateTime? _ValueDateTime;
        /// <summary>
        /// ValueDateTime Property
        /// </summary>
        [DataMember]
        [Browsable(false)]
        public DateTime? ValueDateTime
        {
            get { return _ValueDateTime; }
            set { _ValueDateTime = value; }
        }

        private List<int> _ValueListOfInt;
        /// <summary>
        /// ValueListOfInt Property
        /// </summary>
        [DataMember]
        [Browsable(false)]
        public List<int> ValueListOfInt
        {
            get { return _ValueListOfInt; }
            set { _ValueListOfInt = value; }
        }

        private DataConditionDataTypes _DataType = DataConditionDataTypes.Text;
        /// <summary>
        /// DataType Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public DataConditionDataTypes DataType
        {
            get { return _DataType; }
            set { _DataType = value; }
        }

        private DataCompareTypes _CompareType = DataCompareTypes.Equal;
        /// <summary>
        /// CompareType Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public DataCompareTypes CompareType
        {
            get { return _CompareType; }
            set { _CompareType = value; }
        }

        private bool _CaseSensitive;
        /// <summary>
        /// CaseSensitive Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public bool CaseSensitive
        {
            get { return _CaseSensitive; }
            set { _CaseSensitive = value; }
        }

        private bool _IsNot = false;
        /// <summary>
        /// IsNot Property
        /// </summary>
        [DataMember]
        [Category("Common")]
        public bool IsNot
        {
            get { return _IsNot; }
            set { _IsNot = value; }
        }

        public static string GetDataCompareTypeText(DataCompareTypes compareType)
        {
            string r = "";
            switch (compareType)
            {
                case DataCompareTypes.Equal:
                    r = Properties.Resources.DataCompareType_Equals;
                    break;
                case DataCompareTypes.GreaterThan:
                    r = Properties.Resources.DataCompareType_GreaterThan;
                    break;
                case DataCompareTypes.LowerThan:
                    r = Properties.Resources.DataCompareType_LowerThan;
                    break;
                case DataCompareTypes.GreaterOrEqual:
                    r = Properties.Resources.DataCompareType_GreaterOrEqual;
                    break;
                case DataCompareTypes.LowerOrEqual:
                    r = Properties.Resources.DataCompareType_LowerOrEqual;
                    break;
                case DataCompareTypes.Contains:
                    r = Properties.Resources.DataCompareType_Contains;
                    break;
                case DataCompareTypes.StartsWith:
                    r = Properties.Resources.DataCompareType_StartsWith;
                    break;
                case DataCompareTypes.EndsWith:
                    r = Properties.Resources.DataCompareType_EndsWith;
                    break;
                case DataCompareTypes.Among:
                    r = Properties.Resources.DataCompareType_Among;
                    break;
                case DataCompareTypes.BitwiseAnd:
                    r = Properties.Resources.DataCompareType_BitwiseAnd;
                    break;
                default:
                    break;
            }
            return r;
        }

        public static string GetDataCombinationTypeText(DataConditionCombinationTypes fe1)
        {
            string r = "";
            switch (fe1)
            {
                case DataConditionCombinationTypes.AND:
                    r = Properties.Resources.And;
                    break;
                case DataConditionCombinationTypes.OR:
                    r = Properties.Resources.Or;
                    break;
                default:
                    break;
            }
            return r;
        }

        public object Clone()
        {
            DataCondition r = new DataCondition();
            r.CaseSensitive = CaseSensitive;
            r.ColumnName = ColumnName;
            r.DataType = DataType;
            r.Text = Text;
            r.Category = Category;
            r.CompareType = CompareType;
            r.UI_MaximumHeight = UI_MaximumHeight;
            r.UI_MinimumHeight = UI_MinimumHeight;
            r.UI_IsCustom = UI_IsCustom;
            return r;
        }
    }
}
